/// @description Insert description here
// You can write your code in this editor
//var tmp;
//***AI控制
var tmp;
tmp=1;
if(timer<=0)
{
	timer=64;
	switch(irandom(3))
	{
		case 0:
		if(!scr_crash(0,-1))
		{
			dy=-1;
			dx=0;
			face=1;
		}else timer=0;
		break;
		
		case 1:
		if(!scr_crash(0,1))
		{
			dy=1;
			dx=0;
			face=3;
		}else timer=0;
		break;
		
		case 2:
		if(!scr_crash(-1,0))
		{
			dy=0;
			dx=-1;
			face=2;
		}else timer=0;
		break;
		
		case 3:
		if(!scr_crash(1,0))
		{
			dy=0;
			dx=1;
			face=0;
		}else timer=0;
		break;
		
	}
}else timer-=1;

//***坐标移动
x+=dx*psp;
y+=dy*psp;
//***碰撞检测
if(scr_crash(dx,dy))
{
	timer=0;
	dx=0;
	dy=0;
}

//***动画控制
if(dx!=0||dy!=0)
{
	image_index+=0.2;	
}

//***方向控制

if(instance_exists(obj_player))
{
	if(obj_player.dadouzi>0)
	{
		sprite_index=spr_enemy_blue;
		tmp=0;
	}
	else tmp=1
}

if(tmp)
{
	switch(face)
	{
		case 0:sprite_index=spr_enemy_right;break;
		case 1:sprite_index=spr_enemy_up;break;
		case 2:sprite_index=spr_enemy_left;break;
		case 3:sprite_index=spr_enemy_down;break;
	
	}
}
//边界控制
if(x<16)x=176;
if(x>176)x=16;
	
	
	